#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int res=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){res=(res<<1)+(res<<3)+(c^48);c=getchar();}
	return res*f;
}
void write(int x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
struct node
{
	int nxt,to;
}e[114514];
int head[114514],cnt_edge;
inline void add_edge(int u,int v)
{
	e[++cnt_edge].to=v;
	e[cnt_edge].nxt=head[u];
	head[u]=cnt_edge;
}
int n,m;
int a[114514];
int sum[114514],siz[114514],dfn[114514],cnt;
int ans;
int deg[114514];
void dfs(int u)
{
	siz[u]=1;dfn[u]=++cnt;
	for(int i=head[u];i;i=e[i].nxt)
	{
		int v=e[i].to;
		dfs(v);
		siz[u]+=siz[v];
	}
}
int sp=1;
int main()
{
	freopen("escape.in","r",stdin);
	freopen("escape.out","w",stdout);
	n=read(),m=read();
	for(int i=2;i<=n;i++)
	{
		int u=read();
		add_edge(u,i);
		++deg[u];
	}
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1;i<=n;i++) if(deg[i]>1) sp=0;
	if(sp)
	{
		while(m--)
		{
			int l=read(),r=read();
			write(r-l+1),puts("");
		}
		return 0;
	}
	dfs(1);
	while(m--)
	{
		int l=read(),r=read();
		ans=r-l+1;
		for(int i=1;i<=n;i++) sum[i]=0;
		for(int i=l;i<=r;i++) sum[dfn[a[i]]]=1;
		for(int i=1;i<=n;i++) sum[i]+=sum[i-1];
		for(int i=1;i<=n;i++)
		{
			if(i>=l&&i<=r) continue;
			if(deg[i]<2) continue;
			int flag=0;
			for(int j=head[a[i]];j;j=e[j].nxt)
			{
				int u=e[j].to;
				if(sum[dfn[u]+siz[u]-1]>sum[dfn[u]-1]) ++flag;
			}
			if(flag>=2) ++ans; 
		}
		write(ans),puts("");
	}
	return 0;
}

